//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package javax.vpncrypto;

import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.spec.AlgorithmParameterSpec;
import sun.security.jca.GetInstance.Instance;

public class ExemptionMechanism {
    private Provider provider;
    private javax.vpncrypto.ExemptionMechanismSpi exmechSpi;
    private String mechanism;
    private boolean done = false;
    private boolean initialized = false;
    private Key keyStored = null;

    protected ExemptionMechanism(javax.vpncrypto.ExemptionMechanismSpi var1, Provider var2, String var3) {
        this.exmechSpi = var1;
        this.provider = var2;
        this.mechanism = var3;
    }

    public final String getName() {
        return this.mechanism;
    }

    public static final ExemptionMechanism getInstance(String var0) throws NoSuchAlgorithmException {
        Instance var1 = javax.vpncrypto.JceSecurity.getInstance("ExemptionMechanism", javax.vpncrypto.ExemptionMechanismSpi.class, var0);
        return new ExemptionMechanism((javax.vpncrypto.ExemptionMechanismSpi)var1.impl, var1.provider, var0);
    }

    public static final ExemptionMechanism getInstance(String var0, String var1) throws NoSuchAlgorithmException, NoSuchProviderException {
        Instance var2 = javax.vpncrypto.JceSecurity.getInstance("ExemptionMechanism", javax.vpncrypto.ExemptionMechanismSpi.class, var0, var1);
        return new ExemptionMechanism((javax.vpncrypto.ExemptionMechanismSpi)var2.impl, var2.provider, var0);
    }

    public static final ExemptionMechanism getInstance(String var0, Provider var1) throws NoSuchAlgorithmException {
        Instance var2 = javax.vpncrypto.JceSecurity.getInstance("ExemptionMechanism", javax.vpncrypto.ExemptionMechanismSpi.class, var0, var1);
        return new ExemptionMechanism((ExemptionMechanismSpi)var2.impl, var2.provider, var0);
    }

    public final Provider getProvider() {
        return this.provider;
    }

    public final boolean isCryptoAllowed(Key var1) throws javax.vpncrypto.ExemptionMechanismException {
        boolean var2 = false;
        if (this.done && var1 != null) {
            var2 = this.keyStored.equals(var1);
        }

        return var2;
    }

    public final int getOutputSize(int var1) throws IllegalStateException {
        if (!this.initialized) {
            throw new IllegalStateException("ExemptionMechanism not initialized");
        } else if (var1 < 0) {
            throw new IllegalArgumentException("Input size must be equal to or greater than zero");
        } else {
            return this.exmechSpi.engineGetOutputSize(var1);
        }
    }

    public final void init(Key var1) throws InvalidKeyException, javax.vpncrypto.ExemptionMechanismException {
        this.done = false;
        this.initialized = false;
        this.keyStored = var1;
        this.exmechSpi.engineInit(var1);
        this.initialized = true;
    }

    public final void init(Key var1, AlgorithmParameterSpec var2) throws InvalidKeyException, InvalidAlgorithmParameterException, javax.vpncrypto.ExemptionMechanismException {
        this.done = false;
        this.initialized = false;
        this.keyStored = var1;
        this.exmechSpi.engineInit(var1, var2);
        this.initialized = true;
    }

    public final void init(Key var1, AlgorithmParameters var2) throws InvalidKeyException, InvalidAlgorithmParameterException, javax.vpncrypto.ExemptionMechanismException {
        this.done = false;
        this.initialized = false;
        this.keyStored = var1;
        this.exmechSpi.engineInit(var1, var2);
        this.initialized = true;
    }

    public final byte[] genExemptionBlob() throws IllegalStateException, javax.vpncrypto.ExemptionMechanismException {
        if (!this.initialized) {
            throw new IllegalStateException("ExemptionMechanism not initialized");
        } else {
            byte[] var1 = this.exmechSpi.engineGenExemptionBlob();
            this.done = true;
            return var1;
        }
    }

    public final int genExemptionBlob(byte[] var1) throws IllegalStateException, javax.vpncrypto.ShortBufferException, javax.vpncrypto.ExemptionMechanismException {
        if (!this.initialized) {
            throw new IllegalStateException("ExemptionMechanism not initialized");
        } else {
            int var2 = this.exmechSpi.engineGenExemptionBlob(var1, 0);
            this.done = true;
            return var2;
        }
    }

    public final int genExemptionBlob(byte[] var1, int var2) throws IllegalStateException, ShortBufferException, ExemptionMechanismException {
        if (!this.initialized) {
            throw new IllegalStateException("ExemptionMechanism not initialized");
        } else {
            int var3 = this.exmechSpi.engineGenExemptionBlob(var1, var2);
            this.done = true;
            return var3;
        }
    }

    protected void finalize() {
        this.keyStored = null;
    }
}
